package com.zy.bootdemo.service.impl;

import com.zy.bootdemo.entity.RoomEntity;
import com.zy.bootdemo.mapper.RoomMapper;
import com.zy.bootdemo.mapper.TypeMapper;
import com.zy.bootdemo.service.RoomService;
import com.zy.bootdemo.util.JSONUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.lang.reflect.Type;
import java.util.List;
@Service
public class RoomServicelmpl implements RoomService {
    @Resource
    RoomMapper roomMapper;
    @Resource
    TypeMapper typeMapper;
    @Override
    public List<RoomEntity> selectAll(){
        return roomMapper.selectAll();
    }

    @Override
    public boolean insertOne(String rNum,int rType){
        if(rNum == null || rNum == ""|| rType==0) return  false;
        int rCount = roomMapper.rCount(rType) +1;
        typeMapper.updateCount(rType,rCount);
        return roomMapper.insertOne(rNum,rType)!=0;
    }

    @Override
    public String selectOne(int id) {
        return JSONUtil.getJson(roomMapper.selectOne(id));
    }

   @Override
    public boolean delOne(Integer id){
        if(id == null || id==0) return false;

        return roomMapper.delOne(id) !=0;
    }

    @Override
    public List<RoomEntity> selectByType(Integer id) {
        return roomMapper.selectByType(id);
    }
}
